home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.006.DLog / StandardLib.aii < prev   
Encoding:
Text File  |  1990-06-24  |  7.8 KB  |  371 lines  |  [TEXT/MPS ]

  1. *******************************************************************************
  2. *
  3. * StandardLib.Aii
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Jim Mensch & Keith Rollin
  11. *
  12. * This file contains standard routines used by all the applications on the DTS
  13. * Demo Disk. This file relies on certain data structures being available in a GLOBALS
  14. * data record in the main file.
  15. *
  16. *******************************************************************************
  17.  
  18.     EJECT
  19. *******************************************************************************
  20. *
  21. InitTools    PROC
  22. *
  23. * Description:    Load and initialize the tools needed. Errors are detected
  24. *    and FatalError is called if any occur. If there aren't any
  25. *    errors, the list of menu templates is read and the menu-
  26. *    bar is created.
  27. *
  28. *
  29. * Inputs:    NONE
  30. *
  31. * Outputs:    NONE
  32. *
  33. * External Refs:
  34.     import FatalError
  35. *
  36. * Entry Points:    NONE
  37. *
  38. *******************************************************************************
  39.     with Globals
  40.  
  41. ;
  42. ;   Tool Direct page offsets here
  43. ;
  44. QDDPage    equ $0000
  45. EMDPage    equ QDDPage+$0300
  46. CtlDPage    equ EMDPage+$0100
  47. MenuDPage    equ CtlDPage+$0100
  48. LEDPage    equ MenuDPage+$0100
  49. ToolDPSize    equ LEDPage+$0100
  50.  
  51.     phk    ; Save program bank register and
  52.     plb    ; load it as the data bank register
  53.  
  54.     tdc
  55.     sta MyDP    ; Save direct register
  56.  
  57.     _TLStartup    ; Start Tool Locator
  58.  
  59.     pha    ; Space for result
  60.     _MMStartup    ; Start memory manager
  61.     PullWord MyID    ; Save it for later use
  62.  
  63.     _MTStartup    ; Start up Misc Tools
  64.  
  65.     _IMStartup    ; Start integer math toolset
  66.  
  67.     PushLong #ToolTable    ; Pointer to Tool table
  68.     _LoadTools    ; Load all RAM based tools
  69.     bcc IT0005    ; Carry clear means no error
  70.     brl FatalError    ; Tools can't be loaded. Fatal error!
  71.  
  72. IT0005
  73.  
  74. ; Get memory for Tool Direct pages
  75.  
  76.     pha    ; Room for result
  77.     pha
  78.     PushLong #ToolDPSize; Number of bytes needed
  79.     PushWord MyID    ; ID of this application
  80.     PushWord #attrLocked+attrFixed+attrPage+attrBank
  81.     PushLong #0    ; Allocate them in bank 0
  82.     _NewHandle
  83.     bcc IT0010    ; Test carry for error
  84.     brl FatalError    ; If no memory we got a fatal error!
  85.  
  86. IT0010    PullLong DPHandle    ; Retrieve handle to our DPage area
  87.  
  88.     lda [DPHandle]    ; Dereference the handle to get a ptr
  89.     sta DPPointer    ; to our direct page area and save it.
  90.  
  91.     PushWord DPPointer    ; QuickDraw uses 3 pages of Dpage
  92.     PushWord #ScreenMode; Used to set all master SCB's
  93.     PushWord #0    ; Zero means use default buf size
  94.     PushWord MyID    ; Application ID for allocating data
  95.     _QDStartup    ; Start QuickDraw, turn on SHR Screen
  96.     bcc IT0015
  97.     brl FatalError    ; If it can't be started then bomb
  98.  
  99. IT0015
  100.     lda DPPointer    ; Create address for Event Mgr DPage by
  101.     clc    ; loading in the pointer to the start
  102.     adc #EMDPage    ; of DPage and adding Evt Mgr offset.
  103.     pha    ; Now push it on the stack.
  104.     PushWord #20    ; Size of event queue.
  105.     PushWord #0    ; MouseClamp values.
  106.     PushWord #ScreenWidth ; These will clamp mouse to screen
  107.     PushWord #0    ; area only.
  108.     PushWord #200
  109.     PushWord MyID
  110.     _EMStartup    ; Start the event manager
  111.     bcc IT0020
  112.     brl FatalError    ; Event manager is also a must
  113. IT0020
  114.     PushWord MyID
  115.     _WindStartup
  116.     bcc IT0025
  117.     brl FatalError
  118. IT0025
  119.     PushWord MyID
  120.     lda DPPointer
  121.     clc
  122.     adc #CtlDPage
  123.     pha
  124.     _CtlStartup
  125.     bcc IT0030
  126.     brl FatalError
  127. IT0030
  128.  
  129.     PushWord MyID
  130.     lda DPPointer
  131.     clc
  132.     adc #MenuDPage
  133.     pha
  134.     _MenuStartUp
  135.     bcc IT0035
  136.     brl FatalError
  137. IT0035
  138.     PushWord MyID
  139.     lda DPPointer
  140.     clc
  141.     adc #LEDPage
  142.     pha
  143.     _LEStartUp
  144.     bcc IT0040
  145.     brl FatalError
  146. IT0040
  147.     PushWord MyID
  148.     _DialogStartup
  149.     bcc IT0045
  150.     brl FatalError
  151. IT0045
  152.     _ListStartup
  153.  
  154.     _ScrapStartup    ; No errors possible for this call
  155.  
  156.     _DeskStartup    ; No error possible for this call
  157.  
  158.     PushLong #0
  159.     _RefreshDeskTop
  160.  
  161. ;
  162. ; Create the menus I need
  163. ;
  164.  
  165.     ldx #MenuPtrLen-4    ; Get a pointer to the last menu    
  166. loop    phx    ; Save menu table index on the stack
  167.     pha    ; Push on space for the menu handle
  168.     pha    ;   returned by NewMenu
  169.     lda MenuPtr+2,x    ; Push on the pointer to the template
  170.     pha    ;   to be used by NewMenu when
  171.     lda MenuPtr,x    ;   creating the menu
  172.     pha
  173.     _NewMenu    ; Create a new menu
  174.     PushWord #0    ; Tell InsertMenu where to put it
  175.     _InsertMenu    ; Insert it.
  176.     plx    ; Get our index back off the stack
  177.     dex    ; Point to the next template pointer
  178.     dex
  179.     dex
  180.     dex
  181.     bpl loop    ; Go back up if not done yet.
  182.  
  183.     PushWord #1    ; Add NDA's
  184.     _FixAppleMenu
  185.  
  186.     pha    ; Now call CalcMenuSize for all menus
  187.     _FixMenuBar
  188.     PullWord MenuHeight
  189.  
  190.     _DrawMenuBar    ; Finally, draw it.
  191.  
  192.     RTS
  193.  
  194. ToolTable    dc.W 7    ; Data Block for LoadTools call
  195.     dc.W 14,$0100    ; Window Manager
  196.     dc.W 15,$0100    ; Menu Manager
  197.     dc.W 16,$0100    ; Control Manager
  198.     dc.W 20,$0100    ; LineEdit tool set
  199.     dc.W 21,$0100    ; Dialog Manager
  200.     dc.W 22,$0100    ; Scrap manager
  201.     dc.W 28,$0100    ; List Manager
  202.  
  203.     ENDP
  204.  
  205.     EJECT
  206. *******************************************************************************
  207. *
  208. FatalError    PROC
  209. *
  210. * Description:    Routine that is called whenever a tool sends back an error
  211. *    that can not be recovered from. This routine prints the
  212. *    error on the screen, waits for a keypress then quits back
  213. *    to whoever started this application up!
  214. *
  215. *
  216. * Inputs:    A = Error number
  217. *
  218. * Outputs:    NONE (program exits)
  219. *
  220. * External Refs:
  221.     import CloseTools
  222. *
  223. * Entry Points:    NONE
  224. *
  225. *******************************************************************************
  226.     with Globals
  227.  
  228.     pha    ; Push the error code
  229.     PushLong #ErrNumStr    ; Address of storage area
  230.     PushWord #4    ; Length of string
  231.     _Int2Hex
  232.  
  233.     _GrafOff    ; If QD Started, shut off graphics
  234.  
  235.     PushLong #ErrStr    ; Write error message to the screen
  236.     _WriteCString
  237.  
  238.     pha    ; Space for result
  239.     PushWord #0    ; No echo
  240.     _ReadChar    ; Wait for a key to be pressed
  241.     pla    ; Discard the key
  242.  
  243.     jsr CloseTools    ; Shut down all the tools in case
  244. ;          any got started up
  245.  
  246.     _Quit QuitParms    ; Quit back to where we came from.
  247.  
  248.     brk $FF    ; If the quit fails then just break
  249.     
  250. ErrStr    dc.B 'A fatal error has occured $'
  251. ErrNumStr    dc.B 'xxxx   press any key to exit',0
  252.  
  253.     ENDP
  254.  
  255.     EJECT
  256. *******************************************************************************
  257. *
  258. CloseTools    PROC
  259. *
  260. * Description:    Shut down the tools I started.
  261. *
  262. *
  263. * Inputs:    NONE
  264. *
  265. * Outputs:    NONE
  266. *
  267. * External Refs:    NONE
  268. *
  269. * Entry Points:    NONE
  270. *
  271. *******************************************************************************
  272.     with Globals
  273.  
  274.     _DeskShutDown
  275.     _ScrapShutDown
  276.     _ListShutdown
  277.     _DialogShutDown
  278.     _LEShutDown
  279.     _MenuShutDown
  280.     _CtlShutDown
  281.     _WindShutDown
  282.     _EMShutDown
  283.     _QDShutDown
  284.     _MTShutDown
  285.  
  286.     PushLong DPHandle    ; Dispose of all that DP memory
  287.     _DisposeHandle
  288.  
  289.     PushWord MyID
  290.     _MMShutDown
  291.     _TLShutDown
  292.  
  293.     rts
  294.     ENDP
  295.  
  296.     EJECT
  297. *******************************************************************************
  298. *
  299. doAbout    PROC
  300. *
  301. * Description:    Bring up an Alert Dialog box with our name in it.
  302. *
  303. * Inputs:    NONE
  304. *
  305. * Outputs:    NONE
  306. *
  307. * External Refs:    NONE
  308. *
  309. * Entry Points:    NONE
  310. *
  311. *******************************************************************************
  312.     With Globals
  313.  
  314.     pha    ; space for result
  315.     PushLong #AboutBox    ; pointer to alert template
  316.     PushLong #0    ; pointer to a filter proc (0=none)
  317.     _NoteAlert
  318.     pla    ; get the item hit and dispose
  319.  
  320.     rts
  321.  
  322. ; About Box alert template
  323.  
  324. AboutBox    dc.W 30,30,100,590    ; for 320 use 30,30,100,290
  325.     dc.W 1    ; this is alert # 1
  326.     dc.B $80    ; draw for this stage
  327.     dc.B $81    ; draw for this stage
  328.     dc.B $82    ; draw for this stage
  329.     dc.B $83    ; draw for this stage
  330.     dc.L OKButton    ; ok button for the    alert
  331.     dc.L AboutTitle    ; title of the program
  332.     dc.L AboutAut    ; author
  333.     dc.L AboutVers    ; version number string
  334.     dc.L 0    ; nil to end the list
  335.  
  336. OKBTitle    dc.B 2,'OK'
  337. OKButton    dc.W 1
  338.     dc.W 50,500,65,550
  339.     dc.W buttonItem
  340.     dc.L OKBTitle
  341.     dc.W 0
  342.     dc.W 0    ; item flag
  343.     dc.L 0    ; no color table
  344.  
  345. AboutTitle    dc.W 2
  346.     dc.W 10,100,20,550
  347.     dc.W statText+itemDisable
  348.     dc.L TitleString
  349.     dc.W 0
  350.     dc.W 0    ; item flag
  351.     dc.L 0    ; no color table
  352.  
  353. AboutAut    dc.W 3
  354.     dc.W 25,100,35,550
  355.     dc.W statText+itemDisable
  356.     dc.L AutString
  357.     dc.W 0
  358.     dc.W 0    ; item flag
  359.     dc.L 0    ; no color table
  360.  
  361. AboutVers    dc.W 4
  362.     dc.W 40,100,50,550
  363.     dc.W statText+itemDisable
  364.     dc.L VersString
  365.     dc.W 0
  366.     dc.W 0    ; item flag
  367.     dc.L 0    ; no color table
  368.  
  369.     ENDP
  370.  
  371.     PRINT POP